package cc.lj.internal.coupons.application.service;

import cc.lj.internal.core.model.PageBean;
import cc.lj.internal.core.model.PageParam;
import cc.lj.internal.coupons.domain.martcap.model.vo.MartCapDO;
import cc.lj.internal.coupons.domain.martcap.service.IMartCapDomainService;
import cc.lj.internal.coupons.infrastructure.po.MartCapPO;
import cc.lj.internal.coupons.interfaces.dto.MartCapDTO;
import cc.lj.internal.coupons.interfaces.dto.convert.MartCapDTOConvertDO;
import cc.lj.internal.coupons.interfaces.dto.query.MartCapListQuery;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class MartCapAppService {

    @Resource(name = "martCapDomainServiceImpl")
    private IMartCapDomainService service;

    /**
     * 查询列表，没有查询条件，所以配备一个空MartCapListQuery
     * @return
     */
    public PageBean<MartCapDTO> getList(PageParam pageParam) {
        PageParam<MartCapDO> new_pageParam = new PageParam<>();
        new_pageParam.setParam(null);
        new_pageParam.setOrderBy(pageParam.getOrderBy());
        new_pageParam.setPageNum(pageParam.getPageNum());
        new_pageParam.setPageSize(pageParam.getPageSize());

        PageBean<MartCapDO> page = service.getList(new_pageParam);
        List<MartCapDTO> list = page.getRecords().stream().map(t -> MartCapDTOConvertDO.INSTANCE.convert(t)).collect(Collectors.toList());

        PageBean<MartCapDTO> pageBean = PageBean.createPageBean(page.getPageNum(),page.getPageSize(),page.getTotal(),list);
        return pageBean;
    }
}
